package cn.wh.ymcc.controller;

import cn.wh.ymcc.doc.CourseDoc;
import cn.wh.ymcc.dto.CourseSearchDto;
import cn.wh.ymcc.result.JSONResult;

import cn.wh.ymcc.result.PageList;
import cn.wh.ymcc.serivce.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 课程Es相关控制层
 */
@RestController
public class CourseEsController {
    @Autowired
    private ICourseEsService courseEsService;

    /**
     * 保存课程到Es
     * @param doc
     * @return
     */
    @PostMapping("/saveCourse")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        courseEsService.saveCourse(doc);
        return JSONResult.success();
    }

    /**
     * 删除
     * @param courseId
     * @return
     */
    @PostMapping("/deleteCourse/{courseId}")
    public JSONResult deleteCourse(@PathVariable("courseId") Long courseId){
        courseEsService.deleteCourse(courseId);
        return JSONResult.success();
    }


    @RequestMapping(value = "/course/search",method = RequestMethod.POST)
    public PageList<CourseDoc> search(@RequestBody CourseSearchDto dto){
        return courseEsService.search(dto);
    }
}